package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description nursingLevelController
 * @Author Taoxiuli
 * @Date 2024-09-09
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> getListAll(){
       List<NursingLevelVo> nursingLevelVoList = nursingLevelService.getListAll();
        return ResponseResult.success(nursingLevelVoList);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingLevelVo> getById(@PathVariable("id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }
    @GetMapping("/listByPage")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(@ApiParam(value = "护理等级名称")
                                                                    @RequestParam(value = "name", required = false) String name,
                                                                    @ApiParam(value = "护理等级状态：0-禁用，1-启用")
                                                                    @RequestParam(value = "status", required = false) Integer status,
                                                                    @ApiParam(value = "当前页码")
                                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(value = "每页显示数量")
                                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        PageResponse<NursingLevelVo> nursingLevelPageInfo = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingLevelPageInfo);
    }
    @PutMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult addLevel(@ApiParam(value = "护理等级数据传输对象", required = true)
                                       @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.addLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteLevel(@PathVariable("id") Long id){
        nursingLevelService.deleteLevel(id);
        return ResponseResult.success();
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult<NursingLevelVo> updateLevel(@ApiParam(value = "护理等级数据传输对象", required = true)
                                                          @RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.updateLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("更改护理等级状态")
    public ResponseResult updateStatusById(@PathVariable("id") Long id,
                                           @PathVariable("status") Integer status){
        nursingLevelService.updateStatusById(id,status);
        return ResponseResult.success();
    }

}
